<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <h1>操作内容</h1>
    <ul>
        <li>text()：用于获取或者设置标签内容。</li>
        <li>html()：用于获取或者设置标签HTML内容。</li>
    </ul>
    <h2>设置</h2>
    <div class="div1"></div>
    <div class="div1"></div>
    <div class="div2"></div>
    <div class="div2"></div>
    <h2>获取</h2>
    <p class="p1">innerText:p1</p>
    <p class="p1">innerText:p2</p>
    <p class="p2">innerHTML:p1</p>
    <p class="p2">innerHTML:p2</p>
</body>
<script src="../jquery-3.6.0.min.js"></script>
<script>
    $(".div1").text(`<h2>我是h1</h2>`);
    $(".div2").html(`<h2>我是h1</h2>`);

    // 获取所有选中标签的内容
    let str = $(".p1").text();  
    console.log("Str = ",str);

    // 只获取第一个选中标签的HTML内容
    str = $(".p2").html();
    console.log("Str = ",str);
</script>
</html>